<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<title>凭证记账</title>
</head>
<body>	
	<script type="text/javascript">
		var dataGrid;
		$(function() {
			dataGrid = $('#dataGrid').datagrid({
				url : '${pageContext.request.contextPath}/business/accounting/pingzhengjizhang/dataGrid.shtml',
				fit : true,
				border : false,
				pagination : true,
				pageSize : 20,
				pageList : [ 10, 20, 30, 40, 50 ],
				sortName : 'ID',
				sortOrder : 'ASC',
				checkOnSelect : false,
				selectOnCheck : false,
				nowrap : false,
				striped : true,
				rownumbers : true,
				singleSelect : false,
				columns : [ [
				{field: 'id', checkbox: true},
				{field : 'ID',title : '编号',width : 150,hidden : true},
				{field : 'JFFSE',title : '借方发生额',width : 150,sortable : true},
				{field : 'DFFSE',title : '贷方发生额',width : 150,sortable : true},
				{field : 'FJDJS',title : '附件单据数',width : 150,sortable : true},
				{field : 'PZRQ',title : '凭证日期',width : 150,sortable : true},
				{field : 'ZD',title : '制单',width : 150,sortable : true},
				{field : 'JZ',title : '记账',width : 150,sortable : true},
				{field : 'FH',title : '复核',width : 150,sortable : true},
				{field : 'PZZT',title : '凭证状态',width : 150,sortable : true}, 
				{field : 'HZPZH',title : '汇总凭证号',width : 150,sortable : true},
				{field : 'XSPZH',title : '显示凭证号',width : 150,sortable : true},
				{field : 'PZLB',title : '凭证类别',width : 150,sortable : true}
				]],
				toolbar : '#toolbar',
				onLoadSuccess : function() {
					$('#searchForm table').show();
					parent.$.messager.progress('close');
					$(this).datagrid('tooltip');
				},
				onRowContextMenu : function(e, rowIndex, rowData) {
					e.preventDefault();
					$(this).datagrid('unselectAll');
					$(this).datagrid('selectRow', rowIndex);
					$('#menu').menu('show', {
						left : e.pageX,
						top : e.pageY
					});
				}
			});
			
			console.info(dataGrid);
			dataGrid.datagrid('resize');
		});
	//记账的方法
	
		function jizhang(id) {
			var ids = "";
			var items = dataGrid.datagrid('getChecked');
			if(items != 0){
				for(var i = 0; i < items.length; i++) {
					id = items[i].ID;
					ids+=id+",";
				}
				ids = ids.substr(0, ids.length - 1); 
				fuhes = fuhes.substr(0, fuhes.length - 1);
				alert(ids);
				alert(fuhes);
			
				parent.$.messager.confirm('询问', '请问是否对选中单位进行记账？', function(b) {
					if (b) {
						
						parent.$.messager.progress({
							title : '提示',
							text : '数据处理中，请稍后....'
						});
						$.post('${pageContext.request.contextPath}/business/accounting/pingzhengjizhang/update.shtml?ids=' + ids + '&fuhes='+fuhes, {
							id : id
						}, function(result) {
							if (result.success) {
								parent.$.messager.alert('提示', result.msg, 'info');
								dataGrid.datagrid('reload');
							}
							parent.$.messager.progress('close');
						}, 'JSON');
					}
				});
				
			}else{
				$.messager.alert('通知', "请选择一条数据。");
			}
		}
	
		//取消记账的方法
		
		function fanjizhang(id) {
			var ids = "";
			var items = dataGrid.datagrid('getChecked');
			if(items != 0){
				for(var i = 0; i < items.length; i++) {
					id = items[i].ID;
					
					ids+=id+","
				
					
				}
				ids = ids.substr(0, ids.length - 1); 
				alert(ids);
			
				parent.$.messager.confirm('询问', '请问是否取消对选中单位的记账？', function(b) {
					if (b) {
						
						parent.$.messager.progress({
							title : '提示',
							text : '数据处理中，请稍后....'
						});
						$.post('${pageContext.request.contextPath}/business/accounting/pingzhengjizhang/removeUpdate.shtml?ids=' + ids, {
							id : id
						}, function(result) {
							if (result.success) {
								parent.$.messager.alert('提示', result.msg, 'info');
								dataGrid.datagrid('reload');
							}
							parent.$.messager.progress('close');
						}, 'JSON');
					}
				});
				
			}else{
				$.messager.alert('通知', "请选择一条数据。");
			}
		}
	

	
	
		function searchFun() {
			dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
		}
		function cleanFun() {
			$('#searchForm input').val('');
			dataGrid.datagrid('load', {});
		}
		
		
		$('#hsdw').combobox({
			url:'${pageContext.request.contextPath}/business/accounting/pingzhengjizhang/hsdw.shtml',
		    valueField:'ID',
		    textField:'TITLE'
		});
		$('#cwzt').combobox({
			url:'${pageContext.request.contextPath}/business/accounting/pingzhengjizhang/cwzt.shtml',
		    valueField:'ZTDM',
		    textField:'ZTMC'
		});

	</script>
	<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',title:'',border:false" style="height: 100px; overflow: hidden;" >
			<form id="searchForm">
				<table class="form_view_border" bordercolordark="#FFFFFF" bordercolorlight="#45b97c" border="px" cellpadding="0" cellspacing="0" style="">
				<tr>
					<th class="panel-header">核算单位</th>
							<td style="width: 160px">               
                                <input class="easyui-combobox" id="hsdw" name = "HSDW_EQ_STR" style="width: 190px;height: 27px;" data-options="valueField:'ID', textField:'TITLE', panelHeight:'auto'" >  
                            </td>
						<th class="panel-header">财务账套</th>
							<td style="width: 160px">               
                                <input class="easyui-combobox" id="cwzt" name = "ZTDM_EQ_STR" style="width: 190px;height: 27px;" data-options="valueField:'ZTDM', textField:'ZTMC', panelHeight:'auto'" >  
                            </td>
                            <th class="panel-header">凭证编号</th>
						<td style="width: 160px">               
                                <input   name = "XSPZH_START_STR" style="width: 190px;height: 27px;" data-options="valueField:'ID', textField:'TITLE', panelHeight:'auto'" >  
                            </td>
										
						<th class="panel-header">至</th>
					<td style="width: 160px">               
                                <input   name = "XSPZH_END_STR" style="width: 190px;height: 27px;" data-options="valueField:'ID', textField:'TITLE', panelHeight:'auto'" >  
                            </td>
					</tr>
					<tr>
						<th class="panel-header">凭证日期</th>
						<td><input  name="PZRQ_START_DATE_yyyyMMdd"
										class="form_view_input combo easyui-datebox"/></td>
										
						<th class="panel-header">至</th>
						<td><input  name="PZRQ_END_DATE_yyyyMMdd"
										class="form_view_input combo easyui-datebox"/></td>

						
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="dataGrid"></table>
		</div>
	</div>
	<div id="toolbar" style="display: none;">
	        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_add',plain:true" onclick="searchFun();">查询</a>
		    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_add',plain:true" onclick="jizhang();">记账</a>
		    		    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_delete',plain:true" onclick="fanjizhang();">取消记账</a>
		    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_add',plain:true" onclick="searchFun();">重置</a>


	</div>
	<div id="menu" class="easyui-menu" style="width: 120px; display: none;">
			<div onclick="addFun();" data-options="iconCls:'pencil_add'">增加</div>
			<div onclick="deleteFun();" data-options="iconCls:'pencil_delete'">删除</div>
			<div onclick="editFun();" data-options="iconCls:'pencil'">编辑</div>
	</div> 
</body>
</html>